<?php
/**
 * ProjectName: Grapes.
 * Created by LemonZ.
 * FileName: Worksheet.php
 * Date: 2019/2/14
 * Time: 1:59
 * Description:
 */

namespace app\common\model;


class Worksheet extends common{

    /**
     * @param $data
     * @return bool
     */
    function add($data){
        return $this->data($data)->allowField(true)->save();
    }

    /**
     * 全部
     * @param $seller_id
     * @param $page
     * @param $limit
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function sheetlist($seller_id,$page,$limit){

        $result = $this->field('id,job_num,create_time,type,title,status')
            ->where('seller_id','eq',$seller_id)
            ->page($page,$limit)
            ->order("id","desc")
            ->select();
        $count = $this->field('*')
            ->where('seller_id','eq',$seller_id)
            ->count();
        $re['count'] = $count;
        $re['data'] = $result;
        return $re;

    }

    /**
     * 未处理
     * @param $seller_id
     * @param $sta
     * @param $page
     * @param $limit
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function sheetlist1($seller_id,$sta,$page,$limit){

        $result = $this->field('id,job_num,create_time,type,title,status')
            ->where('seller_id','eq',$seller_id)
            ->where('status','eq',$sta)
            ->page($page,$limit)
            ->order("id","desc")
            ->select();
        $count = $this->field('*')
            ->where('seller_id','eq',$seller_id)
            ->where('status','eq',$sta)
            ->count();
        $re['count'] = $count;
        $re['data'] = $result;
        return $re;

    }

    /**
     * 处理中2
     * @param $seller_id
     * @param $sta
     * @param $page
     * @param $limit
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function sheetlist2($seller_id,$sta,$page,$limit){

        $result = $this->field('id,job_num,create_time,type,title,status')
            ->where('seller_id','eq',$seller_id)
            ->where('status','eq',$sta)
            ->page($page,$limit)
            ->order("id","desc")
            ->select();
        $count = $this->field('*')
            ->where('seller_id','eq',$seller_id)
            ->where('status','eq',$sta)
            ->where('status','eq',$sta)
            ->count();
        $re['count'] = $count;
        $re['data'] = $result;
        return $re;
    }

    /**
     * 已处理
     * @param $seller_id
     * @param $sta
     * @param $page
     * @param $limit
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function sheetlist3($seller_id,$sta,$page,$limit){

        $result = $this->field('id,job_num,create_time,type,title,status')
            ->where('seller_id','eq',$seller_id)
            ->where('status','eq',$sta)
            ->page($page,$limit)
            ->order("id","desc")
            ->select();
        $count = $this->field('*')
            ->where('seller_id','eq',$seller_id)
            ->where('status','eq',$sta)
            ->where('status','eq',$sta)
            ->count();
        $re['count'] = $count;
        $re['data'] = $result;
        return $re;
    }

    /**
     * @param $id
     * @param $seller_id
     * @return array|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function wsdetail($id,$seller_id){
        $rel = $this->field('seller_id,job_num,create_time,type,title,status,content')
            ->where('id','eq',$id)
            ->find();

        if($rel['seller_id'] !=$seller_id){
            return '';
        }else{
            return $rel;
        }

    }

    /**
     * 更改工单状态
     * @param $job_num
     * @return int|string
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    function updata($job_num){
        $result = $this->where('job_num','eq',$job_num)
            ->update(['status' => '已处理']);

        return $result;
    }

    /**
     * 删除工单
     * @param $id
     * @return int
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    function del($id){
        $result = $this->where('id','eq',$id)
            ->delete();
        return $result;
    }

}